var share_div='<div style="background-color:rgba(52, 52, 52, 0.6);position: fixed;width: 100%;height: 100%;z-index: 100;top: 0px;bottom: 0px;text-align: center;">';
	share_div+='<div style="background:url(http://101.wxb315.com/wact/resources/img/share_1.png) no-repeat top center;background-size: 95%;width: 100%;height: 50%;"></div>';
	share_div+='<button onclick="javascript:share_div.remove()" style="width: 203px;height: 84px;background:url(http://101.wxb315.com/wact/resources/img/share_btn.png) no-repeat;border: none;"></button>';
	share_div+='</div>';
	share_div=$(share_div);
$.getScript("http://res.wx.qq.com/open/js/jweixin-1.0.0.js",function(data){
	initWxconfig();
});
function initWxconfig(){
	 $.ajax({
	     url:"http://101.wxb315.com/wxue/api/wx/jsapi",
	     dataType:'jsonp',
	     processData: false, 
	     type:'POST',
	     jsonp: "callback",
	     data:"callback=?",
	     success:function(data){
	    	 wx.config({
	 		    debug: false, 
	 		    appId: data.content.appId, 
	 		    timestamp: data.content.timestamp, 
	 		    nonceStr: data.content.nonceStr, 
	 		    signature: data.content.signature,
	 		    jsApiList: [
	 		                'checkJsApi',
	 		                'onMenuShareTimeline',
	 		                'onMenuShareAppMessage',
	 		                'onMenuShareQQ',
	 		                'onMenuShareWeibo',
	 		                'onMenuShareQZone',
	 		                'hideMenuItems',
	 		                'showMenuItems',
	 		                'hideAllNonBaseMenuItem',
	 		                'showAllNonBaseMenuItem',
	 		                'translateVoice',
	 		                'startRecord',
	 		                'stopRecord',
	 		                'onVoiceRecordEnd',
	 		                'playVoice',
	 		                'onVoicePlayEnd',
	 		                'pauseVoice',
	 		                'stopVoice',
	 		                'uploadVoice',
	 		                'downloadVoice',
	 		                'chooseImage',
	 		                'previewImage',
	 		                'uploadImage',
	 		                'downloadImage',
	 		                'getNetworkType',
	 		                'openLocation',
	 		                'getLocation',
	 		                'hideOptionMenu',
	 		                'showOptionMenu',
	 		                'closeWindow',
	 		                'scanQRCode',
	 		                'chooseWXPay',
	 		                'openProductSpecificView',
	 		                'addCard',
	 		                'chooseCard',
	 		                'openCard'
	 			              ]
	 			});
	     }
	 });
}
function share(params){
	var data="openId="+params.openid+"&key="+params.key+"&url="+location.href+"&callback=?"
	 $.ajax({
	     url:"http://101.wxb315.com/wxue/api/gen_short_url",
	     dataType:'jsonp',
	     processData: false, 
	     jsonp: "callback",
	     data:data,
	     success:function(data){
	    	 share_div.appendTo($(document.body));
	    	 wx.onMenuShareTimeline({
	 		    title: params.title, 
	 		    link: data.content, // 分享链接
	 		    imgUrl: params.img,
	 		    success: function () { 
	 		    	confirm_share(data.key); 
	 		    }
	 		});
	    	 wx.onMenuShareAppMessage({
	    		 title: params.title, 
	    		 desc: params.desc==null?'':params.desc, 
	    		 link: data.content, 
	    		 imgUrl: params.img,
	    		 success: function () { 
	    			 confirm_share(data.key); 
	    		 }
	    	});
	    	wx.onMenuShareQQ({
	    		 title: params.title, 
	    		 desc: params.desc==null?'':params.desc, 
	    		 link: data.content, 
	    		 imgUrl: params.img,
	    		 success: function () { 
	    			 confirm_share(data.key); 
	    		 },
	    	});
	    	wx.onMenuShareQZone({
	    		 title: params.title, 
	    		 desc: params.desc==null?'':params.desc, 
	    		 link: data.content, 
	    		 imgUrl: params.img,
	    		 success: function () { 
	    			 confirm_share(data.key); 
	    		 },
	    	});
	    	 
	     }
	 });     
}

function confirm_share(key){
	var data="key="+key+"&callback=?"
	 $.ajax({
	     url:"http://101.wxb315.com/wxue/api/confirm_share",
	     dataType:'jsonp',
	     processData: false, 
	     jsonp: "callback",
	     data:data,
	     success:function(data){}
	 });     
}
